package com.xiyue.lenovo.propagation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button bn = (Button) findViewById(R.id.bn);
        //为bn绑定事件监听器
        bn.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                //只处理按下键的事件
                if(event.getAction()==KeyEvent.ACTION_DOWN){
                    Log.v("-Listener-","the onKeyDown in Listener");
                }
                //返回false表明事件不会向外扩散
                return false;
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        super.onKeyDown(keyCode, event);
        Log.v("-Activity-","the onKeyDown in Activity");
        //返回false，表明费时间为完全处理该事件，该事件依然向外扩散
        return  false;
    }
}
